//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
#ifndef __BOOT_DISPLAY_H
#define __BOOT_DISPLAY_H

#include <bootDevice.h>

#ifdef __cplusplus
extern "C" {
#endif

//------------------------------------------------------------------------------
// Aliases

#define BOOT_DISPLAY_INIT           BOOT_DEVICE_INIT

//------------------------------------------------------------------------------

enum BOOT_DISPLAY_IOCTL {
    BOOT_DISPLAY_IOCTL_FILLRECT = 0x00020001,
    BOOT_DISPLAY_IOCTL_BLTRECT  = 0x00020002,
    BOOT_DISPLAY_IOCTL_BLTBMP   = 0x00020003,
    BOOT_DISPLAY_IOCTL_COPYRECT = 0x00020004,
    BOOT_DISPLAY_IOCTL_GETPROPS = 0x00020005,
    BOOT_DISPLAY_IOCTL_SLEEP    = 0x00020101,
    BOOT_DISPLAY_IOCTL_AWAKE    = 0x00020102
};

typedef struct BOOT_DISPLAY_FILLRECT_PARAMS {
    RECT* pRect;
    UINT32 color;
} BOOT_DISPLAY_FILLRECT_PARAMS;

typedef struct BOOT_DISPLAY_BLTRECT_PARAMS {
    RECT* pRect;
    VOID* pBuffer;
} BOOT_DISPLAY_BLTRECT_PARAMS;

typedef struct BOOT_DISPLAY_COPYRECT_PARAMS {
    RECT* pRectSrc;
    RECT* pRectDst;
} BOOT_DISPLAY_COPYRECT_PARAMS;

typedef struct BOOT_DISPLAY_GETPROPS_PARAMS {
    UINT32* pWidth;
    UINT32* pHeight;
    UINT32* pBpp;
} BOOT_DISPLAY_GETPROPS_PARAMS;

//------------------------------------------------------------------------------
//
//  Function: BootDisplayInit
//
//  This is proxy for BOOT_DEVICE_PFN_INIT function.
//
__inline
HANDLE
BootDisplayInit(
    BOOT_DEVICE_INIT* pInit
    )
{
    BOOT_DEVICE_IFC* pIfc = NULL;
    
    if (!pInit->pfnInit(pInit->pContext, pInit->contextSize, &pIfc))
        {
        pIfc = NULL;
        }
    return pIfc;
}

//------------------------------------------------------------------------------
//
//  Function:  BootDisplayDeinit
//
__inline
BOOL
BootDisplayDeinit(
    HANDLE hDisplay
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    return pIfc->pfnDeinit(pIfc->hDevice);
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayFillRect(
    HANDLE hDisplay,
    RECT* pRect,
    UINT32 color
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    BOOT_DISPLAY_FILLRECT_PARAMS params;
    
    params.pRect = pRect;
    params.color = color;
    return pIfc->pfnIoCtl(
        pIfc->hDevice, BOOT_DISPLAY_IOCTL_FILLRECT, &params, sizeof(params)
        );
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayBltRect(
    HANDLE hDisplay,
    RECT* pRect,
    VOID* pBuffer
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    BOOT_DISPLAY_BLTRECT_PARAMS params;

    params.pRect = pRect;
    params.pBuffer = pBuffer;
    return pIfc->pfnIoCtl(
        pIfc->hDevice, BOOT_DISPLAY_IOCTL_BLTRECT, &params, sizeof(params)
        );
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayBltBmp(
    HANDLE hDisplay,
    RECT* pRect,
    VOID* pBuffer
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    BOOT_DISPLAY_BLTRECT_PARAMS params;

    params.pRect = pRect;
    params.pBuffer = pBuffer;
    return pIfc->pfnIoCtl(
        pIfc->hDevice, BOOT_DISPLAY_IOCTL_BLTBMP, &params, sizeof(params)
        );
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayCopyRect(
    HANDLE hDisplay,
    RECT* pRectSrc,
    RECT* pRectDst
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    BOOT_DISPLAY_COPYRECT_PARAMS params;

    params.pRectSrc = pRectSrc;
    params.pRectDst = pRectDst;
    return pIfc->pfnIoCtl(
        pIfc->hDevice, BOOT_DISPLAY_IOCTL_COPYRECT, &params, sizeof(params)
        );
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayGetProps(
    HANDLE hDisplay,
    UINT32* pWidth,
    UINT32* pHeight,
    UINT32* pBpp
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    BOOT_DISPLAY_GETPROPS_PARAMS params;

    if (pWidth == NULL || pHeight == NULL || pBpp == NULL) 
        return FALSE;

    params.pWidth  = pWidth;
    params.pHeight = pHeight;
    params.pBpp    = pBpp;
    return pIfc->pfnIoCtl(
        pIfc->hDevice, BOOT_DISPLAY_IOCTL_GETPROPS, &params, sizeof(params)
        );
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplaySleep(
    HANDLE hDisplay
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    return pIfc->pfnIoCtl(pIfc->hDevice, BOOT_DISPLAY_IOCTL_SLEEP, NULL, 0);
}

//------------------------------------------------------------------------------

__inline
BOOL
BootDisplayAwake(
    HANDLE hDisplay
    )
{
    BOOT_DEVICE_IFC *pIfc = (BOOT_DEVICE_IFC*)hDisplay;
    return pIfc->pfnIoCtl(pIfc->hDevice, BOOT_DISPLAY_IOCTL_AWAKE, NULL, 0);
}

//------------------------------------------------------------------------------

#ifdef __cplusplus
}
#endif

#endif // __BOOT_DISPLAY_H

